//第一种方法,原地交换
class Solution {
    public int[] exchange(int[] nums) {
        int len = nums.length;
        int odd = 0;
        int even = len - 1;
        while(odd < even){
            while(odd < even && nums[odd] % 2 != 0){
                odd++;
            }
            while(odd < even && nums[even] % 2 == 0){
                even--;
            }
            int tmp = nums[odd];
            nums[odd] = nums[even];
            nums[even] = tmp;
        }
        return nums;
    }
}

//第二种方法,利用双指针以及新建的数组进行填充.
class Solution {
    public int[] exchange(int[] nums) {
        int len = nums.length;
        int[] res = new int[len];
        int left = 0;
        int right = len - 1;
        for(int num : nums){
            if(num % 2 == 0){
                res[right--] = num;
            }else{
                res[left++] = num;
            }
        }
        return res;
    }
}




